import 'package:built_collection/built_collection.dart';
import 'package:chopper/chopper.dart';
import 'package:hello_flutter/demo/chopper_demo/data/built_value_converter.dart';
import '../model/built_post.dart';
part 'post_api_service.chopper.dart';

@ChopperApi(baseUrl: '/posts')
abstract class PostApiService extends ChopperService {
  @Get(headers: {'x-api-key': '930df713cb974553a2853b79d8e6e983'})
  Future<Response<BuiltList<BuiltPost>>> getPosts();

  @Get(
      path: '/{id}',
      headers: {'x-api-key': '930df713cb974553a2853b79d8e6e983'})
  Future<Response<BuiltPost>> getPost(@Path('id') int id);
  @Post(headers: {'x-api-key': '930df713cb974553a2853b79d8e6e983'})
  Future<Response<BuiltPost>> postPost(@Body() BuiltPost body);

  static PostApiService create() {
    final chopperClient = ChopperClient(
      baseUrl: 'https://d56c0259-cfc8-411a-809b-40e9c3e3d6db.mock.pstmn.io',
      services: [_$PostApiService()],
      converter: BuiltValueConverter(),
      interceptors: [HttpLoggingInterceptor()],
    );
    return _$PostApiService(chopperClient);
  }
}
